home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / basic / qbware.exe / DUMP.BAS < prev    next >
BASIC Source File  |  1990-11-30  |  5KB  |  155 lines

  1. '*****************************************************************************
  2.  
  3. 'Copyright (c) 1987,1988 Marcel Madonna
  4.  
  5. 'DUMP.BAS shows how to use the HEXSTR and CHARXLAT functions.  It takes
  6. 'the file specification entered on the command line and proceeds to dump the
  7. 'file to the screen.
  8.  
  9. '
  10. ' ********************* N O T E *************************
  11. '
  12. 'This program cannot be used from the DOS prompt without Microsoft
  13. 'QuickBasic V4.0 and a registered copy of QBWARE.
  14. '
  15. 'To compile it, at the DOS prompt type:
  16.  
  17. '               bc DUMP;
  18. '               link /ex /noe DUMP,,,brun40 qbware;
  19. '               del DUMP.obj
  20. '               del DUMP.map
  21.  
  22. 'To run it fromthe QuickBasic development environment, type:
  23. '
  24. '               qb DUMP /l qbware
  25. '               [Shift] + F5
  26.  
  27. '               qb disphex /l qbfunc.exe;
  28. '               link disphex;
  29. '               del disphex.obj
  30.  
  31. 'DUMP is not very sophisticated and it does not use the any other QBWARE
  32. 'routines so it's easy to modify if you don't have QBWARE/1.
  33.  
  34. 'To run it simply type:
  35. '
  36. '       DUMP AUTOEXEC.BAT
  37.  
  38. 'at the DOS prompt and you will get a dump of youe AUTOEXEC.BAT file - of
  39. 'course it must be in the current directory.
  40.  
  41. '*****************************************************************************
  42.  
  43.     CLS
  44.     LOCATE 1, 1
  45.     PRINT "DUMP - Version 1.0 (C) Copyright 1987,1988 AJM Software"
  46.     LOCATE 3, 1
  47.     Target.File$ = COMMAND$
  48.     IF Target.File$ = "" THEN
  49.         INPUT "Enter a filename:", Target.File$
  50.     END IF
  51.  
  52. ' We need an ASCIIZ string to open the file
  53.  
  54.     Filenum% = 1                    'Just to show you a neat trick
  55.     Reclen% = 512                   'Read 512 bytes at a time
  56.  
  57.     OPEN Target.File$ FOR RANDOM ACCESS READ AS #Filenum% LEN = Reclen%
  58.  
  59.     FIELD #Filenum%, 512 AS Input.Buffer$
  60.  
  61. ' If the file has no length, assume that it was just created by the previous
  62. ' and it was really not on the disk and should be deleted
  63.  
  64.     File.Len# = LOF(Filenum%)        'Need to keep File length
  65.  
  66.     IF File.Len# = 0 THEN
  67.         CLOSE #Filenum%
  68.         KILL Target.File$
  69.         GOTO Invalid.Parameter
  70.     END IF
  71.  
  72. ' Set up the translation table so that all non-printable ASCII codes are
  73. ' changed to a '.'
  74.  
  75.     Xlat.Table$ = STRING$(256, ".")   'Initialize to all '.'
  76.     FOR X% = 33 TO 126                'Fix all displayable codes
  77.         MID$(Xlat.Table$, X% + 1, 1) = CHR$(X%)
  78.     NEXT
  79.  
  80.     COLOR 15, 1
  81.  
  82. ' Initialize some key fields
  83.  
  84.     Rec.Counter% = 1
  85.     GET #Filenum%, Rec.Counter%        'Get the first record
  86.     Text.Out$ = SPACE$(1024)           'Initailize output area
  87.  
  88. ' Retrieve all records until EOF is reached
  89.  
  90.     WHILE NOT EOF(Filenum%) AND X$ <> CHR$(27)
  91.         File.Len# = File.Len# - Reclen% 'Keep track of remaining bytes
  92.         Text.In$ = Input.Buffer$        'Cannot call with Field variables
  93.         CALL HexStr(Text.In$, Text.Out$) 'convert this record
  94.         CALL CharXlat(Text.In$, Xlat.Table$)  'get rid of non-ASCII
  95.         GOSUB Display.Page
  96.         Rec.Counter% = Rec.Counter% + 1
  97.         GET #Filenum%, Rec.Counter%        'Get the next record
  98.     WEND
  99.  
  100. ' If we reached EOF then we need to print the last record that was retrieved
  101.  
  102.     IF X$ <> CHR$(27) AND File.Len# <> 0 THEN
  103.         Text.In$ = Input.Buffer$        'Cannot call with Field variables
  104.         CALL HexStr(Text.In$, Text.Out$) 'convert this record
  105.         CALL CharXlat(Text.In$, Xlat.Table$)  'get rid of non-ASCII
  106.         MID$(Text.In$, File.Len# + 1, Reclen% - File.Len#) = SPACE$(Reclen% - File.Len#)
  107.         MID$(Text.Out$, (File.Len# * 2) + 1, (Reclen% - File.Len#) * 2) = SPACE$((Reclen% - File.Len#) * 2)
  108.         GOSUB Display.Page
  109.     END IF
  110.     CLOSE #Filenum%
  111.  
  112.     END
  113.  
  114.  
  115. ' Displays a page of text onto the screen
  116.  
  117.  
  118.  
  119. Display.Page:
  120.  
  121.     CLS                     'Clear screen
  122.     LOCATE 1, 1
  123.     PRINT Target.File$; TAB(50); "Relative Sector "; Rec.Counter%
  124.  
  125.     Hex.Text% = 1
  126.     Chr.Text% = 1
  127.     Buffer.Count% = 1
  128.  
  129.     FOR Line.Count% = 1 TO 22                   'Max characters on a page
  130.         Output.Line$ = SPACE$(80)         'Clear output line
  131.  
  132.         FOR Line.Control% = 0 TO 5        'Groups on a line
  133.             MID$(Output.Line$, (Line.Control% * 8) + Line.Control% + 1, 8) = MID$(Text.Out$, Hex.Text%, 8)
  134.             Hex.Text% = Hex.Text% + 8
  135.         NEXT Line.Control%
  136.  
  137.  
  138.         MID$(Output.Line$, 55, 24) = MID$(Text.In$, Chr.Text%, 24)
  139.         Chr.Text% = Chr.Text% + 24
  140.         PRINT Output.Line$
  141.     NEXT Line.Count%
  142.  
  143.     LOCATE 24, 20: PRINT "Press any key to continue - [Esc] to end";
  144.     X$ = ""
  145.     WHILE X$ = ""
  146.         X$ = INKEY$
  147.     WEND
  148.  
  149.     RETURN
  150.  
  151. Invalid.Parameter:
  152.     PRINT Target.File$ + " not found"
  153.     END
  154.  
  155.